package offer;

import java.util.Stack;

public class Offer9 {
    //CQueue obj = new CQueue();
    //obj.appendTail(1);
    //int param_2 = obj.deleteHead();

    class CQueue {
        //正序
        private Stack<Integer> stack;
        //逆序
        private Stack<Integer> reverseStack;

        public CQueue() {
            this.stack = new Stack<Integer>();
            this.reverseStack = new Stack<Integer>();
        }

        public void appendTail(int value) {
            this.stack.push(value);
        }

        public int deleteHead() {
            if (this.reverseStack.empty() && !this.stack.empty()) {
                while(!this.stack.empty()){
                    this.reverseStack.push(this.stack.pop());
                }
            }

            if (this.reverseStack.empty()){
                return -1;
            }

            return this.reverseStack.pop();
        }
    }
}
